import json
import requests

class yuyin():
    def __init__(self):
        self.Apikey='LVMPnolK6xlQOjSKbzY7QHn9'
        self.Secretkey='6MogGDkJKSxojmI3Ma1dM9FE8aUXFOMu'
        self.tokenurl='https://aip.baidubce.com/oauth/2.0/token'
    def get_token(self):
        response=requests.post(self.tokenurl,params={'grant_type':'client_credentials','client_id':self.Apikey,'client_secret':self.Secretkey})
        print(response.json)
        return response.json()

    def get_listion(self, tex):
        tok=yuyinai.get_token()
        url='http://tsn.baidu.com/text2audio'
        audio_ctrl='{"sampling_rate":16000}'
        pompt=f"""
        {url}?tex={tex}&lan=zh&cuid={1}&ctp=1&aue=3&tok={tok["access_token"]}&audio_ctrl={audio_ctrl}&per=4149
        """
        return requests.get(pompt).content

yuyinai=yuyin()